/*
 * LayerMan.cpp
 *
 *  Created on: 28 nov. 2012
 *      Author: johan
 */

#include "LayerMan.h"
#include "Layer.h"

namespace ge {

	LayerMan::LayerMan(int size)
			: size(size)
	{
		layers.reserve(size);
		for (int i = 0; i < size; ++i) {
			Layer* toAdd = new Layer();
			layers.push_back(toAdd);
		}
	}

	void LayerMan::resize(int newSize) {
		if (size == newSize)
			return;
		if (newSize > size) {
			layers.reserve(size);
			for (int i = 0; i < size; ++i) {
				Layer* toAdd = new Layer();
				layers.push_back(toAdd);
			}
		}
	}

	void LayerMan::render(){
		for(Layer * l : layers){
			l->render();
		}
	}



	bool LayerMan::addRenderableToLayer(ui8 layerId, Renderable * elt) {
		assert(layerId>=0, "identificateur de couche foireux...");
		assert(layerId<layers.size(), "identificateur de couche foireux...");
		return layers[layerId]->addRenderable(elt);
	}

	bool LayerMan::delRenderableFromLayer(ui8 layerId, Renderable * elt) {
		assert(layerId>=0, "identificateur de couche foireux...");
		assert(layerId<layers.size(), "identificateur de couche foireux...");
		return layers[layerId]->delRenderable(elt);
	}

	void LayerMan::setVisibilityToLayer(ui8 layerId, bool visibility) {
		assert(layerId>=0, "identificateur de couche foireux...");
		assert(layerId<layers.size(), "identificateur de couche foireux...");
		layers[layerId]->setVisible(visibility);
	}

	bool LayerMan::getVisibilityOfLayer(ui8 layerId) const {
		assert(layerId>=0, "identificateur de couche foireux...");
		assert(layerId<layers.size(), "identificateur de couche foireux...");
		return layers[layerId]->getVisible();
	}

	LayerMan::~LayerMan() {
		for (int i = 0; i < size; ++i) {
			delete layers[i];
		}
	}

} /* namespace ge */
